package persistence.repository;

import persistence.PersistenceController;
import persistence.Persistent;
import util.Log;
import util.Subsystem;
import domain.message.Thread;

/**
 * repository for threads.
 *
 * @author idan
 */
public class ThreadRepository extends Repository<Thread>
{
	/**
	 * @param persistence persistence provider to store objects.
	 * @pre 'persistence' persists objects of type 'Thread'.
	 */
	public ThreadRepository(final PersistenceController persistence)
	{
		super(persistence) ;
	}

	/**
	 * @param topic topic of the new thread.
	 * @return the newly created thread.
	 * @post thread exists in the repository.
	 */
	public Thread create(final String topic)
	{
		final Thread thread = new Thread(Persistent.INVALID_ID, topic) ;
		this.put(thread) ;
		Log.getLogger(Subsystem.REPOSITORY).finest("thread " + thread + " created.") ;
		return thread ;
	}
}